var t = getApp(), e = require("../../mybehaviors/imageSrcP");

Component({
    behaviors: [ e ],
    properties: {
        goods: {
            type: null
        },
        styleCon: {
            type: null
        },
        loading: {
            type: null
        },
        jumpSo: {
            type: null
        },
        storeId: {
            type: null
        },
        classifyBol: {
            type: null
        },
        showprice: {
            type: null
        },
        text: {
            type: null
        },
        kind: {
            type: null
        },
        goods_template: {
            type: null
        },
        goods_style_set: {
            type: null
        },
        type: {
            type: null
        },
        orderField: {
            type: null
        },
        bg_color: {
            type: String,
            value: "#f5f5f5"
        },
        machineId: {
            type: null
        }
    },
    data: {
        language: "",
        iPnoneBottomBol: !1,
        price: "",
        market_price: "",
        template: "",
        maxPrice: "",
        posterId: 0,
        integral: "积分"
    },
    observers: {
        classifyBol: function(t) {
            console.log(t, "aaaaaa");
        },
        goods_template: function(t) {
            console.log(t, "goods_template"), t && (this.setData({
                template: t.names
            }), this.data.classifyBol || this.setData({
                classifyBol: !1
            }));
        },
        orderField: function(t) {
            this.setData({
                maxPrice: t
            });
        }
    },
    lifetimes: {
        attached: function() {
            var t = wx.getStorageSync("langIndex"), e = wx.getStorageSync("yz_basic_info").home.mailInfo.scribing_show && 1 == wx.getStorageSync("yz_basic_info").home.mailInfo.scribing_show ? 1 : 0;
            if (this.setData({
                language: t.en,
                thumb_parameter: this.getyz_basic_info(),
                scribing_show: e
            }), wx.getStorageSync("yz_basic_info").lang) {
                var a = wx.getStorageSync("yz_basic_info").lang.goods, o = a ? a.price : "现价", i = a ? a.market_price : "原价", n = a && a.vip_price ? a.vip_price : "会员价";
                this.setData({
                    price: o,
                    market_price: i,
                    vip_price_txt: n
                });
            }
            var s = wx.getStorageSync("integral");
            s && this.setData({
                integral: s
            });
        },
        moved: function() {},
        detached: function() {}
    },
    attached: function() {
        this.getiPnoneBottom();
    },
    ready: function() {},
    pageLifetimes: {
        show: function() {},
        hide: function() {},
        resize: function() {}
    },
    methods: {
        copybtn: function(t) {
            var e = t.target.dataset.title, a = t.target.dataset.link;
            if (a) {
                var o = a.split("0x0A").join("\r");
                wx.setClipboardData({
                    data: a ? o : ""
                });
            } else wx.setClipboardData({
                data: e || ""
            });
        },
        getiPnoneBottom: function() {
            try {
                wx.getStorageSync("iPhoneBottom") && this.setData({
                    iPnoneBottomBol: !0
                });
            } catch (t) {}
        },
        getShare: function(e) {
            var a = this, o = t.getNetAddresss("goods.goods.get-goods-type");
            o += "&id=" + e, t._getNetWork({
                showToastIn: !1,
                url: o,
                success: function(t) {
                    var o = t.data;
                    if (1 == o.result) {
                        var i = o.data.goods_type, n = o.data.title;
                        a.triggerEvent("getShare", {
                            ras: e,
                            _data: i,
                            groups_title: n
                        });
                    }
                },
                fail: function(t) {}
            });
        },
        gotoDetail: function(t) {
            var e = t.currentTarget.dataset.goodsid || t.currentTarget.dataset.id;
            if (1 == this.data.jumpSo) wx.navigateTo({
                url: "/packageA/detail_v2/detail_v2?id=" + e + "&tag=o2o&store_id=" + this.data.storeId
            }); else {
                if ("snatchRegiment" == this.data.type) return void wx.navigateTo({
                    url: "/packageA/detail_v2/detail_v2?id=" + e + "&name=69"
                });
                "paddingOrder_Home" == this.data.text || "kind" == this.data.kind ? wx.navigateTo({
                    url: "/packageA/detail_v2/detail_v2?id=" + e + "&kind=POrder"
                }) : this.data.machineId ? wx.navigateTo({
                    url: "/packageA/detail_v2/detail_v2?id=" + e + "&machineId=" + this.data.machineId
                }) : wx.navigateTo({
                    url: "/packageA/detail_v2/detail_v2?id=" + e
                });
            }
        },
        saveImg: function() {
            wx.getSetting({
                success: function(t) {
                    t.authSetting["scope.writePhotosAlbum"] || wx.authorize({
                        scope: "scope.writePhotosAlbum",
                        success: function() {
                            console.log("授权成功");
                        }
                    });
                }
            });
            var t = this.data.posterImg.image_url;
            wx.downloadFile({
                url: t,
                success: function(t) {
                    wx.saveImageToPhotosAlbum({
                        filePath: t.tempFilePath,
                        success: function(t) {
                            wx.showToast({
                                title: "保存成功",
                                icon: "none",
                                duration: 2e3
                            });
                        },
                        fail: function(t) {
                            "saveImageToPhotosAlbum:fail auth deny" === t.errMsg && (console.log("当初用户拒绝，再次发起授权"), 
                            wx.openSetting({
                                success: function(t) {
                                    t.authSetting["scope.writePhotosAlbum"] ? wx.showToast({
                                        icon: "none",
                                        title: "获取权限成功,再次长按保存图片",
                                        duration: 1500
                                    }) : wx.showToast({
                                        icon: "none",
                                        title: "获取权限失败,保存图片需要用户授权",
                                        duration: 1500
                                    });
                                }
                            }));
                        },
                        complete: function(t) {
                            console.log(t);
                        }
                    });
                }
            });
        },
        posterClose: function() {
            this.setData({
                posterShow: !1
            });
        },
        postShow: function(t) {
            var e = t.currentTarget.dataset.goodsid;
            this.getShare(e), this.setData({
                posterId: e,
                posterShow: !0
            });
        }
    }
});